home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
recio202.zip
/
usage.txt
< prev
next >
Wrap
Text File
|
1994-05-05
|
23KB
|
665 lines
Title: STANDARD USAGE OF C LANGUAGE RECIO LIBRARY
Copyright: (C) 1994 William Pierpoint
Version: 2.02
Date: May 5, 1994
1.0 INTRODUCTION
The implementation descibed by this standard usage is a superset of the
recio specification. Enhancements are noted in the text.
1.1 Mnemonics
The recio functions have been given a consistent mnemonic naming
convention. All recio functions are in lower case and start with
the letter r. Function names are analogous to <stdio.h> functions.
Mnemonics are as follows:
Single letter (field functions) Multi-letter
---------------------------------------- -----------------
b - base (prefix) beg - beginning
c - column (prefix), character (suffix) ch - character
d - double (suffix) col - column
f - float (suffix) cxt - context
i - integer (suffix) eof - end of file
l - long (suffix) err - error
n - number fld - field buffer
r - record pointer (first letter) fn - function
s - string pointer (suffix) no - number
u - unsigned (suffix) rec - record buffer
siz - size of buffer
str - string
txt - text
1.2 Order
The order in which the prefix mnemonics appear indicates the order in which
the arguments appear in the function. The suffix mnemonics of the input
functions tell you what the function returns. The suffix mnemonics of the
output functions indicate the last argument and tell you what the function
outputs. All output functions return an integer with a zero value if the
function executed successfully.
For example, the input function rbgetui():
arguments: r - record pointer
b - base (radix) of input
returns: ui - unsigned integer
The output function rbputui():
arguments: r - record pointer
b - base (radix) of input
ui - unsigned integer is output
Note: c is used in the prefix of a function's name only once even if there are
two column arguments. If the function inputs or outputs a character,
there is only one column argument; otherwise there are two.
2.0 ERROR AND WARNING CHECKING
The functions declared in the header <recio.h> make use of the errno macro
defined in section 4.1.3 of ANSI X3.159-1989. This mechanism was chosen
because (1) the <stdlib.h> conversion functions (strtod(), strtol(), etc.)
make use of this error reporting mechanism and (2) the <recio.h> functions
make use of the <stdlib.h> conversion functions.
In this implementation, errno can return the following macro constants:
0 - No error.
EACCES - permission denied.
EINVAL - invalid argument (usually null record pointer).
EMFILE - too many open files.
ENOENT - no such file or directory.
ENOMEM - out of memory.
Beginning with version 1.1, recio functions set errno when the record
pointer is invalid and set an internal error number when the record pointer
is valid. The recio error number is accessed through the rerror function.
The rerror function can return the following macro constants:
0 - No error.
R_EINVAL - invalid argument (not the record pointer).
R_EINVDAT - invalid data.
R_EINVMOD - invalid mode.
R_EMISDAT - missing data.
R_ENOMEM - out of memory.
R_ENOPUT - unable to write data to output.
R_ERANGE - data out of range.
Beginning with version 2.0, recio functions set an internal warning number
when the record pointer is valid. The recio library never sets the warning
number when the record pointer is invalid. The recio warning number is
accessed through the rwarning function.
The rwarning function can return the following macro constants:
0 - No warning.
R_WEMPSTR - empty data string.
R_WNOREG - unable to register exit function with atexit().
R_WWIDTH - data too wide for columnar output.
2.1 Define Callback Error Function
First define a callback error function to be used by the recio functions.
You may give the function any name you wish. In the sample function below,
the name rerrfn is used. The function takes one argument, a record pointer
(REC *). It returns nothing (void). The function must first check for a
valid record pointer using the risvalid function. Other than that, you can
customize it to do whatever you want.
The recio functions use a callback error function in order to give the
most flexibility in handling errors. This rerrfn function just sends
information to stderr. You may wish to send information to a printer,
a file, a window, or a dialog box. You might even want to give users
the ability to examine errors and enter corrections. If the error is
corrected, you will want to call the rclearerr function before your
callback error function returns.
When your callback error function is invoked, check rerror() or errno
to determine the cause of the error.
Symbolic errno constants:
* EACCESS means that you don't have permission to access this file. All
MSDOS files have read permission.
* EINVAL indicates an invalid argument to a function, usually a NULL record
pointer. This resulted from a programming error.
* EMFILE means the program tried to open more files than the maximum allotted
by ROPEN_MAX or FOPEN_MAX. If your program is interactive, the user can
close one or more open record streams. Or you might decide that ROPEN_MAX
or FOPEN_MAX needs to be a larger value.
* ENOENT says that ropen() could not find the requested file to open.
Perhaps the name of the file was misspelled, or your program looked in
wrong directory. If your program was trying to read a configuration file,
it could use internal default values when the configuration file does
not exist.
* ENOMEM indicates that the program ran out of heap space. You may be able
to correct this if you are able to deallocate memory you no longer need.
For example, you could reduce the size of buffers when the size only
affects speed. Such buffers need to be flushed first. Buffers used by
the recio library do not fit this criteria.
Symbolic rerror() constants:
* R_EINVDAT says the data is invalid. Invalid data is caused by an
unrecognized character in the field. For example, rgetui() doesn't
expect to see a negative sign, so a negative number will be flagged as
invalid data.
* R_EINVMOD indicates that you opened a file in read mode, then used an output
function or opened a file in write or append mode, then used an input
function.
* R_EMISDAT says the data is missing. Missing data means the field is empty.
If you expect a number, you could substitute either zero or some unique
number to indicate an empty field.
* R_ENOMEM indicates that the program ran out of heap space. You may be able
to correct this if you are able to deallocate memory you no longer need.
For example, you could reduce the size of buffers when the size only
affects speed. Such buffers need to be flushed first. Buffers used by
the recio library do not fit this criteria.
* R_ENOPUT says the program was unable to write the data to output. This
could indicate that the disk is full.
* R_ERANGE tells you that the data is outside the range of the function.
For instance, suppose you used rgeti() to get an integer and the data
value is 32768. If a 16-bit integer has an upper limit of 32767, the
value is too large. If the data is wrong, you can have the error
function correct it. If the data is right, you have to correct the
data type in the program.
The main purpose of this sample callback error function is to show some of
kinds of things you can do in a callback error function. Note that when an
error occurs, the column number indicator rcolno() has moved just beyond
the error. To make it clearer to the user where